using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
//Imports System.Data
using MySql.Data.MySqlClient;
using System.Windows.Forms;
//Imports System.Data.SqlClient
//Imports System.Data.mysql
namespace revoStore
{
    public class SQL
    {
        //Dim connStr As String = "DRIVER={MySQL mysql 5.1 Driver};SERVER=localhost;UID=admin;DATABASE=bdd;Password=admin"
        string connStr = "server=localhost;user=root;database=world;port=3306;password=******;";

        MySqlConnection Connection;
        public SQL(string host, string user, string pass, string db)
        {
            connStr = "server=" + host + ";user=" + user + ";database=" + db + ";password=" + pass + ";";

            Connection = new MySqlConnection();
            Connection.ConnectionString = connStr;
            Connection.Open();
        }



        public string GetQuery(string query)
        {
            try
            {
                //Dim connection As New MySqlConnection(ConnexionSql)
                MySqlCommand cmd = new MySqlCommand(query, Connection);

                Connection.Open();

                MySqlDataReader reader = default(MySqlDataReader);
                reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    //Les champs à recup. Les tables commencent à 0.
                    //Champs = ((reader.GetString(0)))
                    return reader.GetString(0);
                }

                reader.Close();
                Connection.Close();
                return null;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return null;
            }
        }

        public string[] GetRow(string query)
        {
            try
            {
                //Dim connection As New MySqlConnection(ConnexionSql)
                MySqlCommand cmd = new MySqlCommand(query, Connection);

                Connection.Open();

                MySqlDataReader objreader = default(MySqlDataReader);
                objreader = cmd.ExecuteReader();










                while (objreader.Read())
                {
                    //Les champs à recup. Les tables commencent à 0.
                    //Champs = ((reader.GetString(0)))
                    return new string[] {
					(string)objreader[0],
					(string)objreader[1],
					(string)objreader[2],
					(string)objreader[3],
					(string)objreader[4],
					(string)objreader[5]
				};
                }

                objreader.Close();
                Connection.Close();
                return null;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return null;
            }
        }
    }
}